使用IntelliJ IDEA配置Erlang开发环境

您所在的位置:网站首页 idea project sdk is not defined 使用IntelliJ IDEA配置Erlang开发环境

使用IntelliJ IDEA配置Erlang开发环境

2024-01-07 08:10| 来源: 网络整理| 查看: 265

使用IntelliJ IDEA配置Erlang开发环境

https://www.cnblogs.com/jasonduan/p/5175660.html

转自:http://blog.csdn.net/witton/article/details/50551022

Idea工具是目前我使用过的开发Erlang最好用的IDE,但其Erlang插件的官方教程太简陋,我就想自己做一个相对详细的教程。我们来看看如何使用IDEA配置一个开发Erlang的环境:

首先,我们需要安装Erlang的插件,如下图所示,点击Install JetBrains plugin按钮,安装Erlang插件。

 

安装好插件后,还需要配置一下Rebar,如下图所示:

 

然后再选中下图所示的复选框,选择了这两项,我们才能使用Rebar进行编译,并且可以调试

 

配置好上述环境后,我们就可以新建Erlang项目了,如下图所示,选择新建Erlang项目,选择项目的SDK,这里我选择的Erlang 18,然后给项目取名字。

项目建好后,需要建一个spider.app.src文件(spider是Application的名字)以及一个rebar.config,这样才能使用Rebar进行编译,其具体配置如下图所示:

配置好使用Rebar进行编译项目的相关文件后,就可以配置编译工具的参数 了,如上图所示,在点击红色区域内的“Edit configurations”进行配置的编辑,再进行如下图所示的操作,添加 “Erlang Rebar”配置项,修改配置的名称、添加编译的命令compile以及选择支持的模块。

 

 

配置好后,就可以编译了,完成后,会在Project中增加如下图所示的目录及相应的文件。

 

 

配置好编译设置后,我们需要如下图所示添加并配置Erlang的应用,注意添加应用开始的模块、函数,以及需要配置工作目录,否则不能运行。

 

此时我们就可以编译、运行Erlang项目了,也可以进行调试,但是目前我们修改了代码需要手动编译一次,才能生效进行调试运行。可以进行下图所示的设置在启动应用前引用另一个配置进行Rebar的编译,使修改的代码立即生效。

 

 

我们在编写代码的时候,很多时候是需要帮助的,如查看某个系统函数的参数及用 法,我们只需要将光标移动到函数名中,使用Ctrl+Q就可以查看。但这里一个问题,Erlang插件默认的配置是直接从互联网上进行搜索显示的,就像 VS的在线MSDN一样,如果网络状况不佳,就会导致显示很慢,IDEA表现得很卡。可以通过如下图所示的方法添加本地搜索目录,并把网络搜索路径删除, 这样设置后查阅帮助就会变得很快了。

 

通过上面的设置我们现在大功告成,终于可以随心所欲地进行编辑、编译、断点、调试了,如下图所示,我们可以断点,单步执行,查看A、B变量的值,以及查看程序的输出。

 

 

http://ignatov.github.io/intellij-erlang/

intellij-erlang Erlang plugin for IntelliJ IDEA Key features Intelligent Editor for Erlang with code completion, syntax and error highlighting and code inspectionsCode Navigation: project and file structure views, quick jumping between files, modules, functions and usagesTools and frameworks integration: support for Eunit and RebarVCS Integrations: out-of-the-box support for Subversion, Git and MercurialCross-platform: works on Windows, Mac OS X and Linux Installation Download the latest IntelliJ IDEA build and install itSetup the latest version of Erlang plugin from Configure > Plugins > Browse Repositories... > ErlangRestart IntelliJ IDEA.Done! You can import your existing Erlang project or create the new one. Donations

If you would like to make a donation you can use PayPal.

How-tos User Interface

Very nice guide about IntelliJ user interface.

Erlang SDK setup

You need to specify a directory that contains bin directory with erl and erlc executables inside.  Also that directory should contains releases dir inside.  Some predefined paths:

/usr/lib/erlang (Linux)/opt/local/lib/erlang (Mac Ports on Mac OS X)/usr/local/Cellar/erlang/R*/lib/erlang (Homebrew on Mac OS X)

If something goes wrong you always may reopen the #31.

Rebar integration

First of all, you need to provide the right path to the Rebar executable (Settings > Erlang External Tools). 

Note for Mac OS X users. Please, check that the PATH for IntelliJ contains rebar executable. For further information see Stackoverflow answer and #189 issue.

Note for Windows users. Please checkout how to install rebar for Windows.

After you have set your rebar path up you can create a new Rebar run configuration(Run > Edit run configurations...),  use a little green button on the top left corner:

Or execute an existing one (Run > Run...) 

You may create run configuration for every command which Rebar supports, e.g. compile or clean, etc.

Skip dependencies checkbox adds skip_deps=true command for Rebar executable. 

To run eunit tests with rebar you can either create a Rebar Eunit run configuration or use a right-click context menu item 'Run ...' or 'Create ...' having clicked on a module(s), a unit test or a generator function you want to run. 

Rebar-based Eunit test runner: 

To set rebar as a default build action make sure you have checked Compile project with rebar checkbox:

After that your project will be built with 'rebar compile' command when you run Build > Make Project. Compilation result: 

Project structure

In version 0.5 we've added additonal per-module configuration parameters(see Project Structure > Modules). There you can setup your modules' include paths and global parse transformations.

Debugger

Version 0.5 introduces experimental Erlang debugger support. In order to use debugger you need to have debug_info checkbox under Settings > Compiler > Erlang Compiler checked. You also need an Erlang Application run configuration which will be used by debugger. Such configuration can be created by right-clicking on entry point function. Then you can use this configuration to debug your program: The debugger requires Erlang Port Mapper Daemon (epmd) to be running. If it's not up, a warning will be issued. To start the daemon run any Erlang node on your machine, for example with erl -sname foo -s init stop -noshell command.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3